package com.example.xutils;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class Main2Activity extends AppCompatActivity {
    private int[] img = new int[]{R.drawable.safe, R.drawable.app, R.drawable.callmsgsafe, R.drawable.taskmanager, R.drawable.trojan, R.drawable.atools, R.drawable.sysoptimize, R.drawable.netmanager, R.drawable.settings};
    private String[] title = new String[]{"手机防盗", "软件管家", "通讯卫士", "进程管理", "病毒查杀", "高级工具", "缓存清理", "流量监控", "系统设置"};
    private GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        gridView = (GridView) findViewById(R.id.gridView);
        gridView.setAdapter(new gridAdapter());
    }

    private class gridAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return img.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
          convertView = LayoutInflater.from(Main2Activity.this).inflate(R.layout.layout, parent, false);
          ImageView imgV = convertView.findViewById(R.id.img);
          TextView titleV = convertView.findViewById(R.id.title);
          imgV.setImageResource(img[position]);
          titleV.setText(title[position]);
          return convertView;
        }
    }
}
